package com.example.phonestore.controller;

import com.example.phonestore.entity.Address;
import com.example.phonestore.service.AddressService;
import com.example.phonestore.service.UserService;
import com.example.phonestore.util.JsonResult;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("address")
public class AddressController extends BaseController{

    @Autowired
    private AddressService addressService;


    @RequestMapping("insertAddress")
    public JsonResult insertAddress(Address address,HttpSession session){
        Integer uid=getuidFromSession(session);
        System.out.println(uid);
        return addressService.insertAddress(uid,address);
    }
    @RequestMapping({"/",""})
    public List<Address> getAddressByUid(HttpSession session){
        List<Address> data=addressService.getAddressByUid(getuidFromSession(session));
        return data;
    }

    @RequestMapping("{aid}/deleteOneAddress")
    public JsonResult deleteOneAddress(@PathVariable("aid") Integer aid){
        return addressService.deleteOneAddress(aid);
    }
}
